package cn.ecut.tbjie.service;

import cn.ecut.tbjie.dao.PeopleDao;
import cn.ecut.tbjie.utils.GenerateRNum;
import cn.ecut.tbjie.utils.Hex2BinaryUtil;
import cn.ecut.tbjie.utils.MD5Encrypt;
import cn.ecut.tbjie.utils.SaltBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Date;

@Service
public class LoginService {

    @Autowired
    PeopleDao dao;

    /**
     * 获取随机插入位数组
     * @param integer 密码位数
     * @return 随机插入位数组的
     */
    public String getRandom(Integer integer){
        GenerateRNum generateRNum = new GenerateRNum();
        int[] rArray = generateRNum.getRArray(integer);
        return Arrays.toString(rArray) ;
    }

    /**
     * 生成一个新的盐值
     * @return
     */
    public String getSalt(){
        return SaltBuilder.getSalt();
    }

    public boolean verifyPassword(String oldPasswordMD5,int id){
        String oldBPsw = Hex2BinaryUtil.hexString2binaryString(oldPasswordMD5);
        String psw = dao.getPasswordById(id);
        return psw.equals(oldBPsw);
    }
}
